﻿using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using Teigha.Core;

namespace Teigha.TD
{
	public class OdDbUnderlayItem : OdRxObject
	{
		[EditorBrowsable(EditorBrowsableState.Never)]
		public OdDbUnderlayItem(IntPtr cPtr, bool cMemoryOwn) : base(TD_DbPINVOKE.OdDbUnderlayItem_SWIGUpcast(cPtr), cMemoryOwn)
		{
			this.swigCPtr = new HandleRef(this, cPtr);
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		public static HandleRef getCPtr(OdDbUnderlayItem obj)
		{
			if (obj != null)
			{
				return obj.swigCPtr;
			}
			return new HandleRef(null, IntPtr.Zero);
		}

		~OdDbUnderlayItem()
		{
			this.Dispose();
		}

		public override void Dispose()
		{
			if (this.swigCPtr.Handle != IntPtr.Zero)
			{
				if (this.swigCMemOwn)
				{
					lock (this.locker)
					{
						if (this.swigCPtr.Handle != IntPtr.Zero && this.swigCMemOwn)
						{
							this.swigCMemOwn = false;
							TD_DbPINVOKE.delete_OdDbUnderlayItem(this.swigCPtr);
						}
					}
					this.swigCMemOwn = false;
				}
				this.swigCPtr = new HandleRef(null, IntPtr.Zero);
			}
			GC.SuppressFinalize(this);
			base.Dispose();
		}

		public new static OdDbUnderlayItem cast(OdRxObject pObj)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbUnderlayItem_cast(OdRxObject.getCPtr(pObj));
			OdDbUnderlayItem result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbUnderlayItem)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbUnderlayItem)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbUnderlayItem)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new static OdRxClass desc()
		{
			OdRxClass result = (OdRxClass)Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdDbUnderlayItem_desc(), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual OdRxClass isA()
		{
			OdRxClass result = (OdRxClass)Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdDbUnderlayItem_isA(this.swigCPtr), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public new virtual OdRxObject queryX(OdRxClass protocolClass)
		{
			OdRxObject result = Teigha.Core.Helpers.odrxCreateObjectInternal(TD_DbPINVOKE.OdDbUnderlayItem_queryX(this.swigCPtr, OdRxClass.getCPtr(protocolClass)), false);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public static OdDbUnderlayItem createObject()
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbUnderlayItem_createObject();
			OdDbUnderlayItem result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbUnderlayItem)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbUnderlayItem)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbUnderlayItem)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual string getName()
		{
			string result = TD_DbPINVOKE.OdDbUnderlayItem_getName(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdGiRasterImage getThumbnail()
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbUnderlayItem_getThumbnail(this.swigCPtr);
			OdGiRasterImage result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdGiRasterImage)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdGiRasterImage)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdGiRasterImage)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual void getExtents(OdGePoint2d min, OdGePoint2d max)
		{
			TD_DbPINVOKE.OdDbUnderlayItem_getExtents(this.swigCPtr, OdGePoint2d.getCPtr(min), OdGePoint2d.getCPtr(max));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public virtual UnitsValue getUnits()
		{
			UnitsValue result = (UnitsValue)TD_DbPINVOKE.OdDbUnderlayItem_getUnits(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual bool usingPartialContent()
		{
			bool result = TD_DbPINVOKE.OdDbUnderlayItem_usingPartialContent(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual bool worldDraw(OdGiWorldDraw pWd, OdDbUnderlayDrawContext context)
		{
			bool result = TD_DbPINVOKE.OdDbUnderlayItem_worldDraw(this.swigCPtr, OdGiWorldDraw.getCPtr(pWd), OdDbUnderlayDrawContext.getCPtr(context));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual void viewportDraw(OdGiViewportDraw pVd, OdDbUnderlayDrawContext context)
		{
			TD_DbPINVOKE.OdDbUnderlayItem_viewportDraw(this.swigCPtr, OdGiViewportDraw.getCPtr(pVd), OdDbUnderlayDrawContext.getCPtr(context));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public virtual OdGeMatrix3d modelTransform()
		{
			OdGeMatrix3d result = new OdGeMatrix3d(TD_DbPINVOKE.OdDbUnderlayItem_modelTransform(this.swigCPtr), true);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdResult getOsnapPoints(OdGeMatrix3d modelToWorld, OsnapMode osnapMode, IntPtr gsSelectionMark, OdGePoint3d pickPoint, OdGePoint3d lastPoint, OdGeMatrix3d viewXform, OdGeMatrix3d ucs, OdGePoint3dArray snapPoints, OdIntArray geomIds)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbUnderlayItem_getOsnapPoints(this.swigCPtr, OdGeMatrix3d.getCPtr(modelToWorld), (int)osnapMode, gsSelectionMark, OdGePoint3d.getCPtr(pickPoint), OdGePoint3d.getCPtr(lastPoint), OdGeMatrix3d.getCPtr(viewXform), OdGeMatrix3d.getCPtr(ucs), OdGePoint3dArray.getCPtr(snapPoints), OdIntArray.getCPtr(geomIds).Handle);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdDbEntity getSubEntityAtGsMarker(OdGeMatrix3d modelToWorld, IntPtr gsSelectionMark)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = TD_DbPINVOKE.OdDbUnderlayItem_getSubEntityAtGsMarker(this.swigCPtr, OdGeMatrix3d.getCPtr(modelToWorld), gsSelectionMark);
			OdDbEntity result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdDbEntity)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdDbEntity)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdDbEntity)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdResult intersectWith(OdGeMatrix3d modelToWorld, OdDbEntity pEnt, Intersect intType, OdGePlane projPlane, OdGePoint3dArray points, IntPtr thisGsMarker, IntPtr otherGsMarker)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbUnderlayItem_intersectWith(this.swigCPtr, OdGeMatrix3d.getCPtr(modelToWorld), OdDbEntity.getCPtr(pEnt), (int)intType, OdGePlane.getCPtr(projPlane), OdGePoint3dArray.getCPtr(points), thisGsMarker, otherGsMarker);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual uint underlayLayerCount()
		{
			uint result = TD_DbPINVOKE.OdDbUnderlayItem_underlayLayerCount(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual OdResult getUnderlayLayer(int arg0, OdUnderlayLayer arg1)
		{
			OdResult result = (OdResult)TD_DbPINVOKE.OdDbUnderlayItem_getUnderlayLayer(this.swigCPtr, arg0, OdUnderlayLayer.getCPtr(arg1));
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		private object locker = new object();

		private HandleRef swigCPtr;
	}
}
